package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbCapacityData;
import com.sailfish.springbootdemo.pojo.db2.PcbMaterial;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

public interface PcbMaterialDao {
    @Results(id = "pcbMaterialResultMap", value = {
            @Result(column = "pcb_material_id", property = "pcbMaterialId", jdbcType = JdbcType.INTEGER),
            @Result(column = "electrical_performance_class", property = "electricalPerformanceClass", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_material", property = "pcbMaterial", jdbcType = JdbcType.VARCHAR),
            @Result(column = "copper_foil", property = "copperFoil", jdbcType = JdbcType.VARCHAR),
            @Result(column = "tg", property = "tg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "dk", property = "dk", jdbcType = JdbcType.VARCHAR),
            @Result(column = "df", property = "df", jdbcType = JdbcType.VARCHAR),
            @Result(column = "low_halogen", property = "lowHalogen", jdbcType = JdbcType.VARCHAR),
            @Result(column = "publish_time", property = "publishTime", jdbcType = JdbcType.VARCHAR),
            @Result(column = "layer_numbers_max", property = "layerNumbersMax", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hdi_moulding", property = "hdiMoulding", jdbcType = JdbcType.VARCHAR),
            @Result(column = "board_thick_max", property = "boardThickMax", jdbcType = JdbcType.VARCHAR),
            @Result(column = "bga_pitch_min", property = "bgaPitchMin", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hole_distance_min", property = "holeDistanceMin", jdbcType = JdbcType.VARCHAR),
            @Result(column = "two_oz_layer_numbers", property = "twoOzLayerNumbers", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     * 查询单个
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_MATERIAL +
            "<where> " +
            "<if test='id != null'>" +
            " and pcb_material_id = #{id}" +
            "</if>" +
            "</where> " +
            " order by sort" +
            "</script>")
    List<PcbMaterial> getById(@Param("id") Integer id);

    /*
     *查询指定行数据
     */
    @Select("<script> " +
            "select pcb_material_id, electrical_performance_class, pcb_material, copper_foil, tg, dk, df, low_halogen, publish_time, layer_numbers_max, hdi_moulding, board_thick_max, bga_pitch_min, hole_distance_min, two_oz_layer_numbers, remark, create_time, create_user, update_time, update_user, status, sort " +
            "from " + DB2TableName.PCB_MATERIAL +
            "<where>" +
            "<if test='pcbMaterialId != null'>" +
            "    and pcb_material_id = #{pcbMaterialId}" +
            "</if>" +
            "<if test='electricalPerformanceClass != null and electricalPerformanceClass != \"\" '>" +
            "    and electrical_performance_class = #{electricalPerformanceClass}" +
            "</if>" +
            "<if test='pcbMaterial != null and pcbMaterial != \"\" '>" +
            "    and pcb_material = #{pcbMaterial}" +
            "</if>" +
            "<if test='copperFoil != null and copperFoil != \"\" '>" +
            "    and copper_foil = #{copperFoil}" +
            "</if>" +
            "<if test='tg != null and tg != \"\" '>" +
            "    and tg = #{tg}" +
            "</if>" +
            "<if test='lowHalogen != null and lowHalogen != \"\" '>" +
            "    and low_halogen = #{lowHalogen}" +
            "</if>" +
            "<if test='layerNumbersMax != null and layerNumbersMax != \"\" '>" +
            "    and layer_numbers_max = #{layerNumbersMax}" +
            "</if>" +
            "<if test='hdiMoulding != null and hdiMoulding != \"\" '>" +
            "    and hdi_moulding = #{hdiMoulding}" +
            "</if>" +
            "<if test='boardThickMax != null and boardThickMax != \"\" '>" +
            "    and board_thick_max = #{boardThickMax}" +
            "</if>" +
            "<if test='bgaPitchMin != null and bgaPitchMin != \"\" '>" +
            "    and bga_pitch_min = #{bgaPitchMin}" +
            "</if>" +
            "<if test='holeDistanceMin != null and holeDistanceMin != \"\" '>" +
            "    and hole_distance_min = #{holeDistanceMin}" +
            "</if>" +
            "<if test='twoOzLayerNumbers != null and twoOzLayerNumbers != \"\" '>" +
            "    and two_oz_layer_numbers = #{twoOzLayerNumbers}" +
            "</if>" +
            "<if test='sort != null'>" +
            "    and sort = #{sort}" +
            "</if>" +
            "<if test='status != null'>" +
            "    and status = #{status}" +
            "</if>" +
            "<if test='createTime != null'>" +
            "    and create_time = #{createTime}" +
            "</if>" +
            "<if test='updateTime != null'>" +
            "    and update_time = #{updateTime}" +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "    and create_user = #{createUser}" +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "    and update_user = #{updateUser}" +
            "</if>" +
            "</where>" +
            " order by sort" +
//            "limit #{pageable.offset}, #{pageable.pageSize}"+
            "</script>")
    @ResultMap(value = "pcbMaterialResultMap")
    List<PcbMaterial> getAllByLimit(PcbMaterial pcbMaterial);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_MATERIAL + " (electrical_performance_class, pcb_material, copper_foil, tg, dk, df, low_halogen, publish_time, layer_numbers_max, hdi_moulding, board_thick_max, bga_pitch_min, hole_distance_min, two_oz_layer_numbers, remark, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{electricalPerformanceClass}, #{pcbMaterial}, #{copperFoil}, #{tg}, #{dk}, #{df}, #{lowHalogen}, #{publishTime}, #{layerNumbersMax}, #{hdiMoulding}, #{boardThickMax}, #{bgaPitchMin}, #{holeDistanceMin}, #{twoOzLayerNumbers}, #{remark}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    @Options(useGeneratedKeys = true, keyProperty = "pcb_material_id")
    Integer insert(PcbMaterial param);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_MATERIAL + " where pcb_material_id = #{id} ")
    Integer delete(@Param("id") Integer id);

    @Delete("delete from " + DB2TableName.PCB_MATERIAL + " where  pcb_material_id in " +
            "<foreach collection=\"ids\" item = \"id\" open=\"(\" separator=\",\" close=\")\">  " +
            "#{id} " +
            "</foreach>"
    )
    Integer deleteBatch(@Param("ids") List<Integer> ids);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_MATERIAL +
            "<set>" +
            "<if test='electricalPerformanceClass != null '>" +
            " electrical_performance_class = #{electricalPerformanceClass}," +
            "</if>" +
            "<if test='pcbMaterial != null and pcbMaterial != \"\" '>" +
            "    pcb_material = #{pcbMaterial}," +
            "</if>" +
            "<if test='copperFoil != null and copperFoil != \"\" '>" +
            "    copper_foil = #{copperFoil}," +
            "</if>" +
            "<if test='tg != null and tg != \"\" '>" +
            "   tg  = #{tg}," +
            "</if>" +
            "<if test='dk != null and dk != \"\" '>" +
            "   dk  = #{dk}," +
            "</if>" +
            "<if test='df != null and df != \"\" '>" +
            "   df  = #{df}," +
            "</if>" +
            "<if test='lowHalogen != null and lowHalogen != \"\" '>" +
            "   low_halogen  = #{lowHalogen}," +
            "</if>" +
            "<if test='publishTime != null and publishTime != \"\" '>" +
            "   publish_time  = #{publishTime}," +
            "</if>" +
            "<if test='layerNumbersMax != null and layerNumbersMax != \"\" '>" +
            "   layer_numbers_max  = #{layerNumbersMax}," +
            "</if>" +
            "<if test='hdiMoulding != null and hdiMoulding != \"\" '>" +
            "   hdi_moulding  = #{hdiMoulding}," +
            "</if>" +
            "<if test='boardThickMax != null and boardThickMax != \"\" '>" +
            "   board_thick_max  = #{boardThickMax}," +
            "</if>" +
            "<if test='bgaPitchMin != null and bgaPitchMin != \"\" '>" +
            "   bga_pitch_min  = #{bgaPitchMin}," +
            "</if>" +
            "<if test='holeDistanceMin != null and holeDistanceMin != \"\" '>" +
            "   hole_distance_min  = #{holeDistanceMin}," +
            "</if>" +
            "<if test='twoOzLayerNumbers != null and twoOzLayerNumbers != \"\" '>" +
            "   two_oz_layer_numbers  = #{twoOzLayerNumbers}," +
            "</if>" +
            "<if test='remark != null and remark != \"\" '>" +
            "   remark  = #{remark}," +
            "</if>" +
            "<if test='sort != null'>" +
            "    sort = #{sort}," +
            "</if>" +
            "<if test='status != null'>" +
            "    status = #{status}," +
            "</if>" +
            "<if test='createTime != null'>" +
            "    create_time = #{createTime}," +
            "</if>" +
            "<if test='updateTime != null'>" +
            "    update_time = #{updateTime}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "    create_user = #{createUser}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "    update_user = #{updateUser}," +
            "</if>" +
            "</set>" +
            "where pcb_material_id = #{pcbMaterialId}" +
            "</script>")
    Integer update(PcbMaterial param);
}
